<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *订单管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['status']=$this->order_status;
$tabs=array(
	array('op'=>'list','query'=>'status=100','title'=>'全部拼单'),
	array('op'=>'list','query'=>'status=0','title'=>'未支付'),
	array('op'=>'list','query'=>'status=10','title'=>'拼单中'),
	array('op'=>'list','query'=>'status=1','title'=>'拼单成功'),
	array('op'=>'list','query'=>'status=5','title'=>'拼单失败'),
); 
if($_RQ['op']=='list'){
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'is_team'=>1,'plugin_name'=>'jy_pingdd_pin');
	if(isset($_RQ['status']) && $_RQ['status']!=100){
		$params['status']=intval($_RQ['status']);
		if($params['status']==5){
			$params['status']=array(5,6);
		}
		if($params['status']==1){
			$params['status']=array(1,2,3);
		}
		$return['params']['status']=intval($_RQ['status']);
	}
	if($_RQ['id']){
		$params['teamid']=$_RQ['id'];
		$return['params']['teamid']=intval($_RQ['id']);
	}
	if(!empty($_RQ['goodstitle'])){
		$params2=array('uniacid'=>$_SESSION['uniacid']);
		$params2['title like']='%'.trim($_RQ['goodstitle']).'%';
		$goodsids=pdo_getall('jy_weishop_goods',$params2,'id','id');
		if($goodsids){
			$goodsids=array_keys($goodsids);
			$teamids=pdo_getall('jy_weishop_groups_team',array('goodsid'=>$goodsids,'uniacid'=>$_SESSION['uniacid']),'id','id');
			if($teamids){
				$teamids=array_keys($teamids);
				$params['teamid']=$teamids;
			}
		}
		$return['params']['goodstitle']=$_RQ['goodstitle'];
	}
	//我的团
	//先查询我的订单
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$list=pdo_getslice('jy_weishop_order',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($list){
		foreach($list as $k=>&$item){
			$team=pdo_get('jy_weishop_groups_team',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['teamid']));
			$item['goods']=pdo_get('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$team['goodsid']));
			$item['goods']=$this->model('model')->up_price($item['goods'],$return['pluginset'],true);
			if(!$item['goods']['id']){
				unset($teams[$k]);
			}
			
			$item['member']=cfc('core')->member_show($item['mid']);
			//到期时间
			$pingoods=pdo_get('jy_pingdd_pin_goods',array('uniacid'=>$_SESSION['uniacid'],'goodsid'=>$team['goodsid']));
			$item['endtime']=$pingoods['timeout']*60*60+$team['createtime'];
			$item['goodstitle']=$item['goods']['title'];
			$item['teamnum']=$pingoods['teamnum'];
			if($item['status']==10 && $team['status']==1){
				$item['goodsid']=$team['goodsid'];
				$item['pin_goods']=$pingoods;
				$item['pingid']=$pingoods['id'];
				if($pin_goods['allget']==1){
					$this->model('model')->order_getsuccess($item,$team['goodsid']);
				}else{
					$this->model('model')->order_choufail($item);
				}
				$this->model('model')->order_fanxian($item);
			}
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'[温馨提示]：<red>【每人每天最多中次数】设置后，就算拼中人数==成团人数，或者拼中人数不满设置的【拼中人数】，该客户依然无法拼中，会显示拼单失败！注意这不是BUG</red>','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'teamid','title'=>'团ID','type'=>'string'),
			array('name'=>'id','title'=>'拼ID','type'=>'string'),
			array('name'=>'ordersn','title'=>'订单号','type'=>'string'),
			array('name'=>'member','title'=>'会员信息_Member','type'=>'member'),
			//array('name'=>'groupnum','title'=>'已拼单人数','type'=>'string'),
			array('name'=>'teamnum','title'=>'成团人数','type'=>'string'),
			array('name'=>'goodstitle','title'=>'商品名称','type'=>'string'),
			array('name'=>'createtime','title'=>'开团时间','type'=>'time'),
			//array('name'=>'endtime','title'=>'到期时间','type'=>'time'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
		),'action'=>array(
			array('type'=>'href','action'=>'jy_weishop/order.detail/','title'=>'订单详情_Detail'),
			array('action'=>'jy_weishop/order.express/','title'=>'查看物流','type'=>'href','show'=>array('status'=>2,'expressid >'=>0)),
			array('action'=>'jy_weishop/order.list/fa/','title'=>'发货','type'=>'href','show'=>array('status'=>1,'send_status'=>array(0,11))),
			array('action'=>'jy_weishop/order.list/print/','title'=>'打印','type'=>'post'),
			array('type'=>'post','action'=>'jy_weishop/order.list/shou/','title'=>'确认收货','show'=>array('status'=>2)),			
		)
		),
		'search'=>array(
			array('name'=>'id','title'=>'团ID','type'=>'string','width'=>15),
			array('name'=>'nickname','title'=>'团长昵称','type'=>'string','width'=>15),
			array('name'=>'goodstitle','title'=>'商品名称','type'=>'string','width'=>15),
		)
	);
	$return['htmls']=$htmls;	
	exi($return);
}
